<template>
  <div class="class-main">
    <!-- 搜索部分 -->
    <el-card>
      <div slot="header">
        <span>班级搜索</span>
      </div>
      <el-row>
        <el-col :gutter="20" :span="8">
          <el-input v-model="search.name" placeholder="要搜索的班级名"></el-input>
        </el-col>
        <el-col :span="8">
          <el-select v-model="search.sex" placeholder="选择班级类型">
            <el-option label="前端" value="0"></el-option>
            <el-option label="Ui" value="1"></el-option>
          </el-select>
        </el-col>
        <el-col :span="6" :offset="6" style="text-align: right;">
          <el-button type="danger" size="small" @click="doReset">重置</el-button>
          <el-button type="primary" size="small" @click="doSearch">查询</el-button>
        </el-col>
      </el-row>
    </el-card>
    <!-- 搜索部分结束，下面是列表展示部分 -->
    <el-card>
      <div slot="header">
        <span>班级列表</span>
      </div>
      <div slot="header">
        <el-button type="primary" @click="goAdd">新增</el-button>
      </div>
      <el-table :data="classList" border style="width: 100%">
        <el-table-column fixed type="index" label="#" width="50"></el-table-column>
        <el-table-column prop="className" label="班级名称" width="150"></el-table-column>
        <el-table-column label="班级类型" width="120">
          <template slot-scope="scope">
            <p v-if="scope.row.type=='0'" style="color:blue;text-align:center;">前端</p>
            <p v-else-if="scope.row.type=='1'" style="color:orange;text-align:center;">ui</p>
            <p v-else style="color:red;text-align:center;">未知</p>
          </template>
        </el-table-column>

        <el-table-column prop="addTime" label="开版时间" width="150"></el-table-column>
        <el-table-column prop="endTime" label="结束时间" width="150"></el-table-column>
        <el-table-column prop="desc" label="班级描述" width="300"></el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="goDele(scope.row.id)">删除</el-button>
            <el-button @click="doEdit(scope.row.id)" type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        style="margin-top: 30px;text-align:right;"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.start"
        :page-sizes="page.sizes"
        :page-size="page.limit"
        :total="page.totalCount"
        layout="total, sizes, prev, pager, next, jumper"
      ></el-pagination>
    </el-card>
  </div>
</template>

<script>
import { classList,dele } from "@/api/xy/clazz";
export default {
  name: "class",
  data() {
    return {
      search: {},
      classList: [],
      page: {
        start: 1,
        limit: 6,
        totalCount: 0,
        sizes: [6, 12, 18], // 注意: element 的sizes必须是limit的整倍数
      },
    };
  },
  created() {
    this.getClassList();
  },
  methods: {
    goDele(id){
   this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          dele({ id: id });
        this.getClassList();
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page.start = val;
      this.getClassList();
    },
    getClassList() {
      classList({
        start: this.page.start,
        limit: this.page.limit,
        ...this.search,
      }).then((res) => {
        this.classList = res.data.list;
        this.page.totalCount = res.data.totalRow;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.student-main {
}
</style>
